#ifndef _PYTHON_VOID_H
#define _PYTHON_VOID_H

/** This file contains a bunch of dummy declarations to permit compiling the
Python parser without pulling in too many dependencies. */

#include <stdlib.h> /* For malloc. */

enum PY_TYPE {
	PY_STRING,
	PY_INT,
	PY_LONG,
};

typedef struct
{
	enum PY_TYPE type;
	size_t refcount;
} PyObject;

#define PyString_AS_STRING(ptr) PyString_AsString( (PyObject*) ptr )
char* PyString_AsString( PyObject* obj );
void Py_DECREF( PyObject* obj );
void Py_XDECREF( void* obj );
void Py_INCREF( PyObject* obj );
#define PyString_GET_SIZE( x ) PyString_Size(x)
size_t PyString_Size( const PyObject* obj );
PyObject* PyString_FromStringAndSize( const char* str, size_t len );
PyObject* PyString_InternFromString( const char* str );
int PyString_Check( PyObject* obj );
void PyString_InternInPlace( PyObject** obj );
void PyString_ConcatAndDel( PyObject** destination, PyObject* source );

int _PyString_Resize( PyObject** destination, size_t length );

PyObject* PyLong_FromString(char* str,  char** pend, int base);
PyObject* PyInt_FromLong(long value);

int PyInt_Check(PyObject* obj);
int PyInt_Value(PyObject* obj);

PyObject* PyFloat_FromDouble(double value);

PyObject* PyUnicode_DecodeRawUnicodeEscape(
    const char *string,         /* Raw-Unicode-Escape encoded string */
    int length,                 /* size of string */
    const char *errors          /* error handling */
    );

PyObject* PyUnicode_DecodeUnicodeEscape(
    const char *string,         /* Unicode-Escape encoded string */
    int length,                 /* size of string */
    const char *errors          /* error handling */
    );

void PyErr_BadInternalCall();
void PyErr_NoMemory();

PyObject* PyString_DecodeEscape(const char *s,
                                int len,
                                const char *errors,
                                int unicode,
                                const char *recode_encoding);

#define PyFPE_START_PROTECT(a,b)
#define PyFPE_END_PROTECT(a)

//~ typedef struct
//~ {
//~ } PyTypeObject;

/* Imported from Python.h */
#define Py_single_input 256
#define Py_file_input 257
#define Py_eval_input 258

/* Imported from pythonrun.h. */

#define PyCF_SOURCE_IS_UTF8  0x0100

/* compute parser flags based on compiler flags */
#define PARSER_FLAGS(flags) (flags)->cf_flags

/*(((flags) && (flags)->cf_flags & PyCF_DONT_IMPLY_DEDENT) ? \ PyPARSE_DONT_IMPLY_DEDENT : 0) */


typedef struct {
	int cf_flags;  /* bitmask of CO_xxx flags relevant to future */
} PyCompilerFlags;


#define PyAPI_FUNC(x) x
#define PyAPI_DATA(x) extern x

//~ #define PyObject_HEAD

#define PyObject_Malloc(x) malloc(x)
#define PyObject_Free(x) free(x)

#define PyObject_MALLOC(length) malloc(length)
#define PyObject_REALLOC(pointer, length) realloc(pointer, length)
#define PyObject_FREE(pointer) free(pointer)

#define PyMem_NEW(type, count) ((type*) malloc( sizeof(type)*count ))

#define PyMem_DEL(pointer) free(pointer)
#define PyMem_FREE(pointer) free(pointer)
#define PyMem_RESIZE(pointer, type, count) pointer = realloc(pointer, sizeof(type)*count )

#define PyOS_snprintf snprintf
#define PyOS_strtoul strtoul
#define PyOS_strtol strtol

#define PySys_WriteStderr(string, args...) fprintf( stderr, string, ## args )
#define Py_FatalError(message) assert(0)

#define Py_VerboseFlag 0

//~ extern  *PyOS_Readline(FILE *, FILE *,  *);
#define PyOS_Readline( a, b, c ) NULL

//~ PyObject * PyErr_Occurred(void);
#define PyErr_Occurred() NULL


/* From stringobject.h (modified) */

//~ typedef struct
//~ {
	//~ size_t length;
	//~  buffer[0];
//~ } PyStringObject;

//~ #define PyString_AS_STRING(str) (((PyStringObject *)(str))->buffer)

#define PyErr_Format( obj, format, args... ) assert(0)
#define PyErr_SetString( obj, message ) assert(0)

#endif
